import { rcaNumberFormat0 } from './common.js'
import { commonTableOption } from './common.js'
export const tableOption = {
  ...commonTableOption,
  column: [
    {
      type: 'month',
      label: '统计月份',
      prop: 'statisticsMonth',
      search: true,
      valueFormat: 'yyyy-MM',
    },
    {
      type: 'select',
      label: '运营商',
      prop: 'operators',
      width: "120",
      props: {
        label: 'operatorsName',
        value: 'operators'
      },
      dicUrl: '/rca/swckdiffafterclear/listoperators',
      search: true,
      rules: [
        {
          required: false,
          message: '请选择运营商',
          trigger: 'blur'
        }
      ],
    }, {
      type: 'select',
      label: '线路名称',
      prop: 'lineCode',
      width: "160",
      dicQuery: { allLine: true },
      //dicUrl: '/rca/swckbankcashpaymentnote/listAllSubWayLine',
	   dicUrl: '/support/swparamline/dictsecondname',
      props: {
        label: 'name',
        value: 'code'
      },
      search: true,
      rules: [
        {
          required: false,
          message: '请选择线路',
          trigger: 'blur'
        }
      ],
    },
    {
      label: '单程票',
      children: [
        {
          type: 'input',
          label: '原始清分金额',
          prop: 'lastClearMoneyDCP',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }, {
          type: 'input',
          label: '调整后清分金额',
          prop: 'currClearMoneyDCP',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }, {
          type: 'input',
          label: '清分差异金额',
          prop: 'diffMoneyDCP',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }
      ]
    },
    {
      label: '二维码电子票',
      children: [
        {
          type: 'input',
          label: '原始清分金额',
          prop: 'lastClearMoneyEWM',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }, {
          type: 'input',
          label: '调整后清分金额',
          prop: 'currClearMoneyEWM',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }, {
          type: 'input',
          label: '清分差异金额',
          prop: 'diffMoneyEWM',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }
      ]
    },
    {
      label: '交通一卡通',
      children: [
        {
          type: 'input',
          label: '原始清分金额',
          prop: 'lastClearMoneyJTK',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }, {
          type: 'input',
          label: '调整后清分金额',
          prop: 'currClearMoneyJTK',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }, {
          type: 'input',
          label: '清分差异金额',
          prop: 'diffMoneyJTK',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }
      ]
    },
    {
      label: '长安通',
      children: [
        {
          type: 'input',
          label: '原始清分金额',
          prop: 'lastClearMoneyCAT',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }, {
          type: 'input',
          label: '调整后清分金额',
          prop: 'currClearMoneyCAT',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }, {
          type: 'input',
          label: '清分差异金额',
          prop: 'diffMoneyCAT',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }
      ]
    },
    {
      label: '人脸电子票',
      children: [
        {
          type: 'input',
          label: '原始清分金额',
          prop: 'lastClearMoneyRLDZ',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }, {
          type: 'input',
          label: '调整后清分金额',
          prop: 'currClearMoneyRLDZ',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }, {
          type: 'input',
          label: '清分差异金额',
          prop: 'diffMoneyRLDZ',
          width: "140",
          precision: 7,
          formatter: (row, value, label, column) => {
            return rcaNumberFormat0(value)
          },
        }
      ]
    }
  ]
}


/**
 *  0: {ticketType: "1", ticketTypeName: "单程票"}
    1: {ticketType: "2", ticketTypeName: "二维码电子票"}
    2: {ticketType: "3", ticketTypeName: "交通一卡通"}
    3: {ticketType: "4", ticketTypeName: "长安通"}
    4: {ticketType: "5", ticketTypeName: "人脸电子票"}
 */

function uniqueArray (arr) {
  return Array.from(new Set(arr))
}
export const formatTableData = (data) => {
  const lineArr = uniqueArray(data.map(d => d.lineCode));
  return lineArr.map(lineCode=>{
    const currentData = data.filter(d=>d.lineCode === lineCode);
    const commonInfo = currentData[0];
    if(commonInfo === undefined){
      return null
    }
    return {
      lineCode,
      statisticsMonth: commonInfo.statisticsMonth,
      operators: commonInfo.operators,

      lastClearMoney1: (currentData.find(d=>d.lineCode === lineCode && ticketType === '1') || {}).lastClearMoneyDCP || 0,
      currClearMoney1: (currentData.find(d=>d.lineCode === lineCode && ticketType === '1') || {}).currClearMoneyDCP || 0,
      diffMoney1: (currentData.find(d=>d.lineCode === lineCode && ticketType === '1') || {}).diffMoneyDCP || 0,

      lastClearMoney2: (currentData.find(d=>d.lineCode === lineCode && ticketType === '2') || {}).lastClearMoneyEWM || 0,
      currClearMoney2: (currentData.find(d=>d.lineCode === lineCode && ticketType === '2') || {}).currClearMoneyEWM || 0,
      diffMoney2: (currentData.find(d=>d.lineCode === lineCode && ticketType === '2') || {}).diffMoneyEWM || 0,

      lastClearMoney3: (currentData.find(d=>d.lineCode === lineCode && ticketType === '3') || {}).lastClearMoneyJTK || 0,
      currClearMoney3: (currentData.find(d=>d.lineCode === lineCode && ticketType === '3') || {}).currClearMoneyJTK || 0,
      diffMoney3: (currentData.find(d=>d.lineCode === lineCode && ticketType === '3') || {}).diffMoneyJTK || 0,

      lastClearMoney4: (currentData.find(d=>d.lineCode === lineCode && ticketType === '4') || {}).lastClearMoneyCAT || 0,
      currClearMoney4: (currentData.find(d=>d.lineCode === lineCode && ticketType === '4') || {}).currClearMoneyCAT || 0,
      diffMoney4: (currentData.find(d=>d.lineCode === lineCode && ticketType === '4') || {}).diffMoneyCAT || 0,

      lastClearMoney5: (currentData.find(d=>d.lineCode === lineCode && ticketType === '5') || {}).lastClearMoneyRLDZ || 0,
      currClearMoney5: (currentData.find(d=>d.lineCode === lineCode && ticketType === '5') || {}).currClearMoneyRLDZ || 0,
      diffMoney5: (currentData.find(d=>d.lineCode === lineCode && ticketType === '5') || {}).diffMoneyRLDZ || 0,
    }
  }).filter(d=>d!==null)

}
